#ifndef COLLAGEWINDOW_H
#define COLLAGEWINDOW_H

#include "mylistphotos.h"
#include "parametre.h"

#define M_PI 3.14159

struct zoneImage
{
    QImage      *image;
    QPoint      posImage;
    int         rotation;
};

class CollageWindow
{
    //Q_OBJECT

public:
    CollageWindow();
    ~CollageWindow();
    void addPhoto(QString s,bool filePrefix=false);
    void supprimePhoto();
    void supprimeLesPhotos();
    virtual void on_update_delete();
    virtual void showMessage(QString);
    QPixmap* GetPolygonePixmap(QPolygon*, int width=350, int heigh=350);

    void SetRectangle();
    void SetCercle();
    void ajoutPhotoParDialog(QWidget*);

    MyListPhotos *listPhotos;
    QStringList supportedFormatList;
    Parametre *params;
    QPolygon *polygon;
    QPixmap *pixAnimation;

    //Création du collage
    QPixmap* Collage();

private:
    void aSignal();

    bool RectInsidePolygoneForme(QRect rect, QPoint imagePos, int rotation);

    QList<zoneImage*> fillListZoneImage(int nbrImages, int pictureSize);
    void resetListZoneImage(QList<zoneImage*> listImages);
    QList<zoneImage*> copyListZoneImage(QList<zoneImage*> listImages);
    void destroyListZoneImage(QList<zoneImage*> listImages, bool deleteImage);
    void removeListZoneImage(QList<zoneImage *> *listZoneImage, int nbrImagesToRemove);
    void addListZoneImage(QList<zoneImage*> *listZoneImage, int nbrImagesToAdd, int pictureSize);

    void resizePicture(QImage *image, int pictureSize);
    void resizePicturePx(QImage *image, int pictureSize);
    void resizePictureCm(QImage *image, int pictureSize);

    int convertCmToPixel(int cm);

    bool resizePolygon(QSize resultSize);
    bool replacePolygon(QSize resultSize);

    void collageImage(QList<zoneImage *> listZoneImage, QPixmap* pixmap);
    bool PlacementListZoneImage(QList<zoneImage*> listZoneImage, QSize tailleResult, int sizePicture, int spacingPicture);
    bool PlacementZoneImage(QList<zoneImage*> listZoneImage, zoneImage* zoneImage, QSize tailleResult, int sizePicture, int spacingPicture, QPoint* lastPos);

    bool testEspacement(QList<zoneImage*> listZoneImage, QPoint newPos, QRect recImage, int espacementCible, int tailleImage);

    QPixmap* TailleResultAuto();
    QPixmap* pictureSizeAuto();
    QPixmap* pictureQuantityAuto();
    QPixmap* pictureSpacingAuto();


//signals:
    //void majAnimation();
};

#endif // COLLAGEWINDOW_H
